﻿using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace PepsiCo.Intranet.Receivers.ChildSiteInit
{
    /// <summary>
    /// Web Events
    /// </summary>
    public class ChildSiteInit : SPWebEventReceiver
    {
       /// <summary>
       /// A site is being provisioned.
       /// </summary>
       //public override void WebAdding(SPWebEventProperties properties)
       //{
       //    base.WebAdding(properties);
       //}

       /// <summary>
       /// A site was provisioned.
       /// </summary>
       public override void WebProvisioned(SPWebEventProperties properties)
       {
           base.WebProvisioned(properties);
           try
           {
               using (SPWeb childWeb = properties.Web)
               {
                   SPWeb rootWeb = childWeb.Site.RootWeb;

                   childWeb.MasterUrl = rootWeb.MasterUrl;
                   childWeb.CustomMasterUrl = rootWeb.CustomMasterUrl;
                   childWeb.Update();
               }
           }
           catch (Exception ex)
           {

           }
       }


    }
}
